<?php
namespace Game;

use Game\Entity\Person;
use Symfony\Component\HttpFoundation\Request;
use Game\Exception\Environment\CommandNotDefineException;
/**
 * Description of CommandExecuter
 *
 * @author pahhan
 */
class CommandExecuter
{
    public function execute(Person $person, Request $request)
    {
        $command = $request->get('command');
        if( !$command )
            throw new CommandNotDefineException('There is no "command" parameter in request');

        $action = $person->getAction($command);

        if( $action )
        {
            $action->execute(NULL);
            return $action->render();
        }

        $env = $person->getEnvironment();
        $env->init();

        $result = $env->executeCommand($person, $request);

        return json_encode($result);
    }
}

